package com.example.demo.utils;


import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;

public class MD5Utils {

    private static final String[] digital = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"};

    private static String md5(String text) throws Exception {
        StringBuilder result = new StringBuilder();
        MessageDigest messageDigest = MessageDigest.getInstance("MD5");
        byte[] bytes = messageDigest.digest(text.getBytes(StandardCharsets.UTF_8));
        for (byte info : bytes) {
            int temp = info;
            if (temp < 0) {
                temp = temp + 256;
            }
            int i = temp / 16;
            int j = temp % 16;
            result.append(digital[i]).append(digital[j]);
        }
        //System.out.println(result);
        return result.toString();
    }

    public static String finalMD5(String text) throws Exception {
        String res = md5(text) + "lzp";
        return md5(res);
    }

}
